package com.winning.sjzc.sjjflgl.service.impl;

import com.winning.sjzc.sjjflgl.dao.DataSetClassificationDao;
import com.winning.sjzc.sjjflgl.entity.SJJFL;
import com.winning.sjzc.sjjflgl.service.DataSetClassificationService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class DataSetClassificationServiceImpl implements DataSetClassificationService {

    @Autowired
    private DataSetClassificationDao dscDao;

    @Override
    public List<SJJFL> queryDataSetClassification() {
        Map<String, Object> map =new HashMap<String, Object>();
//        if(StringUtils.isNotBlank(sjymc) ){
//            map.put("sjymc", sjymc);
//        }
        List<SJJFL> list = dscDao.queryDataSetClassification(map);
        return list;
    }

    @Override
    public int saveDataSetClassification(SJJFL sjjfl) {
        String sjjfldm = sjjfl.getSJJFLDM();
        SJJFL qSjjflxx = querySjjflxxBySjydm(sjjfldm);
        if(qSjjflxx != null && qSjjflxx.getSJJFLDM() !=""){
            return -1;
        }
        String yjlbdm = sjjfl.getYJLBDM();
        if(StringUtils.isNotBlank(yjlbdm) ){
             String yjlbmc =querySjjflxxBySjydm(yjlbdm).getSJJFLMC();
            sjjfl.setYJLBMC(yjlbmc);
        }

        String ejlbdm = sjjfl.getEJLBDM();
        if(StringUtils.isNotBlank(ejlbdm) ){
            String ejlbmc =querySjjflxxBySjydm(ejlbdm).getSJJFLMC();
            sjjfl.setEJLBMC(ejlbmc);
        }

        dscDao.saveDataSetClassification(sjjfl);
        return 1;
    }

    @Override
    public void deleteDataSetClassification(String sjjfldm) {
        dscDao.deleteDataSetClassification(sjjfldm);
    }


    public SJJFL querySjjflxxBySjydm(String sjjfldm){
        SJJFL sjjfl=dscDao.querySjjflxxBySjjfldm(sjjfldm);
        return sjjfl;
    }

    @Override
    public void updateDataSetClassification(SJJFL sjjfl){
        String yjlbdm = sjjfl.getYJLBDM();
        if(StringUtils.isNotBlank(yjlbdm) ){
            String yjlbmc =querySjjflxxBySjydm(yjlbdm).getSJJFLMC();
            sjjfl.setYJLBMC(yjlbmc);
        }

        String ejlbdm = sjjfl.getEJLBDM();
        if(StringUtils.isNotBlank(ejlbdm) ){
            String ejlbmc =querySjjflxxBySjydm(ejlbdm).getSJJFLMC();
            sjjfl.setEJLBMC(ejlbmc);
        }
        dscDao.updateDataSetClassification(sjjfl);
    }

}
